package com.dwyinyuan.enums;

import com.dwyinyuan.producer.*;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.concurrent.BlockingQueue;

@Getter
@AllArgsConstructor
public enum ProviderEnums {
    FENG_NIAO("蜂鸟网", "FengniaoProducer") {
        @Override
        public Runnable getProviderClass(BlockingQueue<String> blockingQueue) {
            return new FengniaoProducer(getName(), blockingQueue);
        }
    },
    HUA_SHI_6("画师通", "Huashi6Producer") {
        @Override
        public Runnable getProviderClass(BlockingQueue<String> blockingQueue) {
            return new Huashi6Producer(getName(), blockingQueue);
        }
    },
    MEI_NV_LA("圣光", "MeinvlaProducer") {
        @Override
        public Runnable getProviderClass(BlockingQueue<String> blockingQueue) {
            return new MeinvlaProducer(getName(), blockingQueue);
        }
    },
    TANG_YUN_365("唐韵", "Tangyun365Producer") {
        @Override
        public Runnable getProviderClass(BlockingQueue<String> blockingQueue) {
            return new Tangyun365Producer(getName(), blockingQueue);
        }
    },
    WALL_HAVEN("wallhaven", "WallHavenProducer") {
        @Override
        public Runnable getProviderClass(BlockingQueue<String> blockingQueue) {
            return new WallHavenProducer(getName(), blockingQueue);
        }
    },
    WIN_4000("美桌壁纸", "Win4000Producer") {
        @Override
        public Runnable getProviderClass(BlockingQueue<String> blockingQueue) {
            return new Win4000Producer(getName(), blockingQueue);
        }
    },
    YA_LA_YI("雅拉咿", "YalayiProducer") {
        @Override
        public Runnable getProviderClass(BlockingQueue<String> blockingQueue) {
            return new YalayiProducer(getName(), blockingQueue);
        }
    },
    TU_JIGU("图集谷", "TujiguProducer") {
        @Override
        public Runnable getProviderClass(BlockingQueue<String> blockingQueue) {
            return new TujiguProducer(getName(), blockingQueue);
        }
    },
    ;

    private String desc;//描述
    private String name;//生产者名称


    //获取生产者实例
    public abstract Runnable getProviderClass(BlockingQueue<String> blockingQueue);

    //根据生产者名称获取枚举对象
    public static ProviderEnums getEnumByName(String name) {
        return Arrays.stream(ProviderEnums.values())
                .filter(c -> c.getName().equals(name))
                .findFirst()
                .get();
    }

    //根据生产者名称获取任务
    public static Runnable getTaskByName(String name, BlockingQueue<String> blockingQueue) {
        return getEnumByName(name).getProviderClass(blockingQueue);
    }
}
